/**
 * Created by admin on 2018/1/25.
 */
layui.config({
    base : "../js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    //创建一个编辑器
    var editIndex = layedit.build('help_content');
    var addHelpArray = [],addHelp;
    form.on("submit(addHelp)",function(data){
        //是否添加过信息
        if(window.sessionStorage.getItem("addHelp")){
            addHelpArray = JSON.parse(window.sessionStorage.getItem("addHelp"));
        }


        addHelp = '{"accidentId":"'+$(".accidentId").val()+'",';  //事故编号
        addHelp += '"accidentName":"'+$(".accidentName").val()+'",'; //事故名称
        addHelp += '"timely":"'+$("input[name='timely']:checked").val()+'",'; //救助及时？
        addHelp += '"success":"'+$("input[name='success']:checked").val()+'",'; //救助成功？
        addHelp += '"helpService":"'+$(".helpService").val()+'",'; //救助机构
        addHelp += '"helpBoat":"'+$(".helpBoat").val()+'",'; //救助船只
        addHelp += '"loss":"'+$(".loss").val()+'"}'; //挽回损失
        addHelpArray.unshift(JSON.parse(addHelp));
        window.sessionStorage.setItem("addHelp",JSON.stringify(addHelpArray));
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("文章添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })

})